import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Router } from '@angular/router';
import { ActionSheetConfig, SkinType, ActionSheetService } from 'ngx-weui';
import { ApiService } from 'src/app/core/api';
import { StorageService } from 'src/app/core/sotrage/storage.service';
import { I18nService } from '../../core/i18n/i18n.service';
import { PickerService } from 'ngx-weui/picker';
@Component({
	templateUrl: './index.component.html',
	styleUrls: ['./index.less'],
	encapsulation: ViewEncapsulation.None,
})
export class ConsumptionListComponent implements OnInit {
	constructor(
		private srv: ActionSheetService,
		private datesrv: PickerService,
		private i: I18nService,
		private router: Router,
		private api: ApiService,
		private sto: StorageService) {
		this.i.get(['MSG.register-code', 'MSG.register-user']).subscribe(res => {
			this.msgData = res;
		});
	}
	pageData = {
		"pageNo": "1",
		"time": "2020-02",
		"agencyId": "1"
	}
	config: ActionSheetConfig = {
		title: '',
	} as ActionSheetConfig;

	DT: any = {
		min: new Date(2015, 1, 5),
		max: new Date(),
	  };
	menus: any[] = [
		{ text: '2020-05', value: '2020-05' }, 
		{ text: '2020-04', value: '2020-04' }, 
		{ text: '2020-03', value: '2020-03' }, 
		{ text: '2020-02', value: '2020-02' },
		{ text: '2020-01', value: '2020-01' }
	];
	
	list=[];
	msgData: any;
	ngOnInit() {
		this.getList();
	}
	getList() {
		this.api.post('消费明细', this.pageData).then(res => {
			this.list=res['data']['list'];
		});
	}
	onShow(type: SkinType, backdrop: boolean = true) {
		this.config.skin = type;
		this.config.backdrop = backdrop;
		this.srv.show(this.menus, this.config).subscribe((res: any) => {
			this.pageData.time = res.value;
			this.getList();
		});
	}
	onShowBySrv(type: string){
		this.datesrv.showDateTime('date-ym').subscribe((res: any) => {
			this.pageData.time = res.value;
			this.getList();
		});
	}
	onSave(f) {
		const data = f.value;
		this.api.post('用户注册(2/2 用户银行信息)', data).then(res => {
			this.sto.set('user', res['data']);
			this.router.navigate(['/']);
		});
	}
}

